<template>
  <div class="app-container">
    <el-form :model="searchParams" ref="searchParams" :inline="true">
        <el-form-item label="用户ID">
          <el-input class="input" v-model="searchParams.parentCode" maxlength='20' placeholder="请输入" clearable
            show-word-limit></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSearch" type="primary" icon="el-icon-search"
            style="margin-left:40px">搜索</el-button>
        </el-form-item>
      </el-form>
    <el-row>
      <el-col :span="24" class="top">
        <el-tree ref="tree"
        :data="userList"
        node-key='id'
        :props="defaultProps"
        @node-expand="handleNodeExpand"
        :indent='30'></el-tree>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  finduserTree
} from '@/api/system/user.js'

export default {
  components: {},
  data() {
    return {
      parentId: '',
      searchParams: {},
      userList: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
    }
  },
  created(){
    // this.searchParams.parentId = 40
    this.findUserList()
  },
  methods:{
    handleSearch() {
      this.userList = []
      this.searchParams.parentId = ''
      this.findUserList()
    },
    handleNodeExpand(data) {
        this.searchParams.parentId = data.id
        this.findUserList(data)
    },
    /** 查询用户列表 */
    findUserList(data) {
      this.searchParams.type = 'teamMember'
      finduserTree(this.searchParams).then(res => {
        if(res.data.code == 10000){
          if(this.userList.length==0){
             this.userList = res.data.data.list
          }else{
            data.children = res.data.data.list
          }
        }
      });
    },
  },
}
</script>


<style lang="scss" scoped>

</style>
